import instacne from "../request";
interface IreqOrderList{
  orderSn:string,
    receiverKeyword:string,
    createTime:string,
    status:number | null,
    orderType:number | null,
    sourceType:number | null,
    pageNum?:number,
    pageSize?:number
}
interface IresOrderList{
  list:Array<IOrderList>;
  pageNum:number;
  pageSize:number;
  total:number;
  totalPage:number
}
/**
 * @id 编号
 * @orderSn 订单编号
 * @createTime 创建时间
 * @memberUsername 用户账号
 * @payAmount 支付金额
 * @sourceType 订单来源
 * @status 订单状态
 */
interface IOrderList{
  id:number;
  orderSn:number;
  createTime:string;
  memberUsername:string;
  payAmount:number;
  payType:number;
  sourceType:number;
  status:number;
}
const OrderListAPI = (params:IreqOrderList):Promise<IresOrderList>=>{
  return instacne.get("order/list",{params})
}
// 批量删除订单接口
const OrderDeleteAPI = (params:{ids:Array<number>}):void=>{
   instacne.post(`order/delete?ids=${params.ids.join()}`)
}

// 批量关闭订单接口
const OrderCloseAPI = (params:{ids:Array<number>,note:string}):void=>{
  instacne.post(`order/update/close?ids=${params.ids.join()}&note=${params.note}`)
}

type TreqDelivery = Array<{
  // 发货公司
  deliveryCompany:string,
  // 发货编号
  deliverySn:string,
  // 订单ID
  orderId:number
  }>
// 批量发货
const OrderDeliveryAPI = (params:TreqDelivery):void=>{
  instacne.post("order/update/delivery",params)
}

//获取订单设置
interface IOrderSetting{
  commentOvertime: number,
    confirmOvertime: number,
    finishOvertime: number,
    flashOrderOvertime: number,
    id: number,
    normalOrderOvertime: number
}
const OrderSetting = (parmas:number):Promise<IOrderSetting>=>{
  return instacne.get("orderSetting/"+parmas)
}

// 修改订单设置
 const OrderSettingUpdate = (params:IOrderSetting):void=>{
  instacne.post("orderSetting/update/"+params.id,params)
 }

//  分页查询退货申请
enum statusEnum{
  "待处理"=0,
  "退货中"=1,
  "已完成"=2,
  "已拒绝"=3,
}
interface IreqOrderReturn{
  createTime:string;
  handleMan:string;
  handleTime:string;
  id:number;
  pageNum?:number;
  pageSize?:number;
  receiverKeyword?:string;
  status:statusEnum;
}

interface IOrderReturn{
  id:number;
  createTime:number;
  memberUsername:string;
  productRealPrice:string;
  status:statusEnum;
  handleTime:string;
  [key:string]:string|number|undefined|null;
}
interface IresOrderReturn{
  list:Array<IOrderReturn>;
  pageNum:number;
  pageSize:number;
  total:number;
  totalPage:number
}
const OrderReturnListAPI = (params:IreqOrderReturn):Promise<IresOrderReturn>=>{
  return instacne.get("returnApply/list",{params})
}
// 退货批量删除
const OrderReturnDeleteAPI = (params:Array<number>):void=>{
  instacne.post("returnApply/delete",{data:params})
}
// 退货详情
const OrderReturnDetailAPI = (params:number):any=>{
  return instacne.get("returnApply/"+params)
}

// 分页查询退货原因
interface IreqOrderReturnReson{
  pageNum:number;
  pageSize:number;
}
interface IReturnReson{
  id:number;
  createTime:string;
  name:string;
  sort:number;
  status:number;
}
interface IresOrderReturnReson{
  list:Array<IReturnReson>;
  pageSize:number;
  pageNum:number;
  total:number;
  totalPage:number;
}
const OrderReturnResonListAPI = (params:IreqOrderReturnReson):Promise<IresOrderReturnReson>=>{
  return instacne.get("returnReason/list",{params})
}
// 添加退货原因
const OrderAddReturnResonAPI = (params:IReturnReson):Promise<number>=>{
  return instacne.post("returnReason/create",params)
}
// 批量删除退货原因
const OrderDelReturnResonAPI = (params:Array<number>):Promise<number>=>{
  return instacne.post(`returnReason/delete?ids=${params.join()}`)
}
// 修改原因状态
const OrderUpdateReturnResonStatusAPI = (params:{ids:number,status:number}):void=>{
  instacne.post(`returnReason/update/status?status=${params.status}&ids=${params.ids}`)
}
// 修改退货原因
const OrderUpdateReturnResonAPI = (params:IReturnReson):Promise<number>=>{
  return instacne.post("returnReason/update/"+params.id,params)
}
// 查询单个退货原因
const OrderQueryReturnReasonAPI = (params:number):Promise<IReturnReson>=>{
  return instacne.get("returnReason/"+params)
}

// 收货地址管理
interface IAddressList{
  addressName: string,
      city: string,
      detailAddress: string,
      id: number,
      name: string,
      phone: string,
      province: string,
      receiveStatus: number,
      region: string,
      sendStatus: number
}

const OrderCompanyAddressAPI = ():Promise<IAddressList[]>=>{
  return instacne.get("companyAddress/list")
}

// 获取订单详情
const OrderDetailAPI = (params:number):Promise<any>=>{
  return instacne.get("order/"+params)
}
export {
  OrderListAPI, OrderDeleteAPI, OrderCloseAPI, OrderDeliveryAPI, OrderSetting, OrderSettingUpdate,
  OrderReturnListAPI, OrderReturnDeleteAPI, OrderReturnDetailAPI, OrderReturnResonListAPI, OrderAddReturnResonAPI,
  OrderDelReturnResonAPI, OrderUpdateReturnResonStatusAPI, OrderUpdateReturnResonAPI, OrderQueryReturnReasonAPI,
  OrderCompanyAddressAPI, OrderDetailAPI
};
export type { IreqOrderList, IresOrderList, IOrderList, TreqDelivery, IOrderSetting, IreqOrderReturn, IOrderReturn, IReturnReson };
export { statusEnum };

